<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>hsvpalette.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_ui_hsvpalette.js.html">hsvpalette.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview An HSV (hue/saturation/value) color palette/picker
<a name="line17"></a> * implementation. Inspired by examples like
<a name="line18"></a> * http://johndyer.name/lab/colorpicker/ and the author&#39;s initial work. This
<a name="line19"></a> * control allows for more control in picking colors than a simple swatch-based
<a name="line20"></a> * palette. Without the styles from the demo css file, only a hex color label
<a name="line21"></a> * and input field show up.
<a name="line22"></a> *
<a name="line23"></a> * @author arv@google.com (Erik Arvidsson)
<a name="line24"></a> * @author smcbride@google.com (Sean McBride)
<a name="line25"></a> * @author manucornet@google.com (Manu Cornet)
<a name="line26"></a> * @see ../demos/hsvpalette.html
<a name="line27"></a> */
<a name="line28"></a>
<a name="line29"></a>goog.provide(&#39;goog.ui.HsvPalette&#39;);
<a name="line30"></a>
<a name="line31"></a>goog.require(&#39;goog.color&#39;);
<a name="line32"></a>goog.require(&#39;goog.dom&#39;);
<a name="line33"></a>goog.require(&#39;goog.dom.DomHelper&#39;);
<a name="line34"></a>goog.require(&#39;goog.events&#39;);
<a name="line35"></a>goog.require(&#39;goog.events.Event&#39;);
<a name="line36"></a>goog.require(&#39;goog.events.EventType&#39;);
<a name="line37"></a>goog.require(&#39;goog.events.InputHandler&#39;);
<a name="line38"></a>goog.require(&#39;goog.style&#39;);
<a name="line39"></a>goog.require(&#39;goog.style.bidi&#39;);
<a name="line40"></a>goog.require(&#39;goog.ui.Component&#39;);
<a name="line41"></a>goog.require(&#39;goog.ui.Component.EventType&#39;);
<a name="line42"></a>goog.require(&#39;goog.userAgent&#39;);
<a name="line43"></a>
<a name="line44"></a>
<a name="line45"></a>
<a name="line46"></a>/**
<a name="line47"></a> * Creates an HSV palette. Allows a user to select the hue, saturation and
<a name="line48"></a> * value/brightness.
<a name="line49"></a> * @param {goog.dom.DomHelper=} opt_domHelper Optional DOM helper.
<a name="line50"></a> * @param {string=} opt_color Optional initial color (default is red).
<a name="line51"></a> * @param {string=} opt_class Optional base for creating classnames (default is
<a name="line52"></a> *     goog.getCssName(&#39;goog-hsv-palette&#39;)).
<a name="line53"></a> * @extends {goog.ui.Component}
<a name="line54"></a> * @constructor
<a name="line55"></a> */
<a name="line56"></a>goog.ui.HsvPalette = function(opt_domHelper, opt_color, opt_class) {
<a name="line57"></a>  goog.ui.Component.call(this, opt_domHelper);
<a name="line58"></a>
<a name="line59"></a>  this.setColor_(opt_color || &#39;#f00&#39;);
<a name="line60"></a>
<a name="line61"></a>  /**
<a name="line62"></a>   * The base class name for the component.
<a name="line63"></a>   * @type {string}
<a name="line64"></a>   * @protected
<a name="line65"></a>   */
<a name="line66"></a>  this.className = opt_class || goog.getCssName(&#39;goog-hsv-palette&#39;);
<a name="line67"></a>
<a name="line68"></a>  /**
<a name="line69"></a>   * The document which is being listened to.
<a name="line70"></a>   * type {HTMLDocument}
<a name="line71"></a>   * @private
<a name="line72"></a>   */
<a name="line73"></a>  this.document_ = this.getDomHelper().getDocument();
<a name="line74"></a>};
<a name="line75"></a>goog.inherits(goog.ui.HsvPalette, goog.ui.Component);
<a name="line76"></a>// TODO(user): Make this inherit from goog.ui.Control and split this into
<a name="line77"></a>// a control and a renderer.
<a name="line78"></a>
<a name="line79"></a>
<a name="line80"></a>/**
<a name="line81"></a> * DOM element representing the hue/saturation background image.
<a name="line82"></a> * @type {Element}
<a name="line83"></a> * @private
<a name="line84"></a> */
<a name="line85"></a>goog.ui.HsvPalette.prototype.hsImageEl_;
<a name="line86"></a>
<a name="line87"></a>
<a name="line88"></a>/**
<a name="line89"></a> * DOM element representing the hue/saturation handle.
<a name="line90"></a> * @type {Element}
<a name="line91"></a> * @private
<a name="line92"></a> */
<a name="line93"></a>goog.ui.HsvPalette.prototype.hsHandleEl_;
<a name="line94"></a>
<a name="line95"></a>
<a name="line96"></a>/**
<a name="line97"></a> * DOM element representing the value background image.
<a name="line98"></a> * @type {Element}
<a name="line99"></a> * @protected
<a name="line100"></a> */
<a name="line101"></a>goog.ui.HsvPalette.prototype.valueBackgroundImageElement;
<a name="line102"></a>
<a name="line103"></a>
<a name="line104"></a>/**
<a name="line105"></a> * DOM element representing the value handle.
<a name="line106"></a> * @type {Element}
<a name="line107"></a> * @private
<a name="line108"></a> */
<a name="line109"></a>goog.ui.HsvPalette.prototype.vHandleEl_;
<a name="line110"></a>
<a name="line111"></a>
<a name="line112"></a>/**
<a name="line113"></a> * DOM element representing the current color swatch.
<a name="line114"></a> * @type {Element}
<a name="line115"></a> * @protected
<a name="line116"></a> */
<a name="line117"></a>goog.ui.HsvPalette.prototype.swatchElement;
<a name="line118"></a>
<a name="line119"></a>
<a name="line120"></a>/**
<a name="line121"></a> * DOM element representing the hex color input text field.
<a name="line122"></a> * @type {Element}
<a name="line123"></a> * @protected
<a name="line124"></a> */
<a name="line125"></a>goog.ui.HsvPalette.prototype.inputElement;
<a name="line126"></a>
<a name="line127"></a>
<a name="line128"></a>/**
<a name="line129"></a> * Input handler object for the hex value input field.
<a name="line130"></a> * @type {goog.events.InputHandler}
<a name="line131"></a> * @private
<a name="line132"></a> */
<a name="line133"></a>goog.ui.HsvPalette.prototype.inputHandler_;
<a name="line134"></a>
<a name="line135"></a>
<a name="line136"></a>/**
<a name="line137"></a> * Listener key for the mousemove event (during a drag operation).
<a name="line138"></a> * @type {goog.events.Key}
<a name="line139"></a> * @private
<a name="line140"></a> */
<a name="line141"></a>goog.ui.HsvPalette.prototype.mouseMoveListener_;
<a name="line142"></a>
<a name="line143"></a>
<a name="line144"></a>/**
<a name="line145"></a> * Listener key for the mouseup event (during a drag operation).
<a name="line146"></a> * @type {goog.events.Key}
<a name="line147"></a> * @private
<a name="line148"></a> */
<a name="line149"></a>goog.ui.HsvPalette.prototype.mouseUpListener_;
<a name="line150"></a>
<a name="line151"></a>
<a name="line152"></a>/**
<a name="line153"></a> * Gets the color that is currently selected in this color picker.
<a name="line154"></a> * @return {string} The string of the selected color.
<a name="line155"></a> */
<a name="line156"></a>goog.ui.HsvPalette.prototype.getColor = function() {
<a name="line157"></a>  return this.color_;
<a name="line158"></a>};
<a name="line159"></a>
<a name="line160"></a>
<a name="line161"></a>/**
<a name="line162"></a> * Alpha transparency of the currently selected color, in [0, 1].
<a name="line163"></a> * For the HSV palette this always returns 1. The HSVA palette overrides
<a name="line164"></a> * this method.
<a name="line165"></a> * @return {number} The current alpha value.
<a name="line166"></a> */
<a name="line167"></a>goog.ui.HsvPalette.prototype.getAlpha = function() {
<a name="line168"></a>  return 1;
<a name="line169"></a>};
<a name="line170"></a>
<a name="line171"></a>
<a name="line172"></a>/**
<a name="line173"></a> * Updates the text entry field.
<a name="line174"></a> * @protected
<a name="line175"></a> */
<a name="line176"></a>goog.ui.HsvPalette.prototype.updateInput = function() {
<a name="line177"></a>  var parsed;
<a name="line178"></a>  try {
<a name="line179"></a>    parsed = goog.color.parse(this.inputElement.value).hex;
<a name="line180"></a>  } catch (e) {
<a name="line181"></a>    // ignore
<a name="line182"></a>  }
<a name="line183"></a>  if (this.color_ != parsed) {
<a name="line184"></a>    this.inputElement.value = this.color_;
<a name="line185"></a>  }
<a name="line186"></a>};
<a name="line187"></a>
<a name="line188"></a>
<a name="line189"></a>/**
<a name="line190"></a> * Sets which color is selected and update the UI.
<a name="line191"></a> * @param {string} color The selected color.
<a name="line192"></a> */
<a name="line193"></a>goog.ui.HsvPalette.prototype.setColor = function(color) {
<a name="line194"></a>  if (color != this.color_) {
<a name="line195"></a>    this.setColor_(color);
<a name="line196"></a>    this.updateUi();
<a name="line197"></a>    this.dispatchEvent(goog.ui.Component.EventType.ACTION);
<a name="line198"></a>  }
<a name="line199"></a>};
<a name="line200"></a>
<a name="line201"></a>
<a name="line202"></a>/**
<a name="line203"></a> * Sets which color is selected.
<a name="line204"></a> * @param {string} color The selected color.
<a name="line205"></a> * @private
<a name="line206"></a> */
<a name="line207"></a>goog.ui.HsvPalette.prototype.setColor_ = function(color) {
<a name="line208"></a>  var rgbHex = goog.color.parse(color).hex;
<a name="line209"></a>  var rgbArray = goog.color.hexToRgb(rgbHex);
<a name="line210"></a>  this.hsv_ = goog.color.rgbArrayToHsv(rgbArray);
<a name="line211"></a>  // Hue is divided by 360 because the documentation for goog.color is currently
<a name="line212"></a>  // incorrect.
<a name="line213"></a>  // TODO(user): Fix this, see http://1324469 .
<a name="line214"></a>  this.hsv_[0] = this.hsv_[0] / 360;
<a name="line215"></a>  this.color_ = rgbHex;
<a name="line216"></a>};
<a name="line217"></a>
<a name="line218"></a>
<a name="line219"></a>/**
<a name="line220"></a> * Alters the hue, saturation, and/or value of the currently selected color and
<a name="line221"></a> * updates the UI.
<a name="line222"></a> * @param {?number=} opt_hue (optional) hue in [0, 1].
<a name="line223"></a> * @param {?number=} opt_saturation (optional) saturation in [0, 1].
<a name="line224"></a> * @param {?number=} opt_value (optional) value in [0, 255].
<a name="line225"></a> */
<a name="line226"></a>goog.ui.HsvPalette.prototype.setHsv = function(opt_hue,
<a name="line227"></a>                                               opt_saturation,
<a name="line228"></a>                                               opt_value) {
<a name="line229"></a>  if (opt_hue != null || opt_saturation != null || opt_value != null) {
<a name="line230"></a>    this.setHsv_(opt_hue, opt_saturation, opt_value);
<a name="line231"></a>    this.updateUi();
<a name="line232"></a>    this.dispatchEvent(goog.ui.Component.EventType.ACTION);
<a name="line233"></a>  }
<a name="line234"></a>};
<a name="line235"></a>
<a name="line236"></a>
<a name="line237"></a>/**
<a name="line238"></a> * Alters the hue, saturation, and/or value of the currently selected color.
<a name="line239"></a> * @param {?number=} opt_hue (optional) hue in [0, 1].
<a name="line240"></a> * @param {?number=} opt_saturation (optional) saturation in [0, 1].
<a name="line241"></a> * @param {?number=} opt_value (optional) value in [0, 255].
<a name="line242"></a> * @private
<a name="line243"></a> */
<a name="line244"></a>goog.ui.HsvPalette.prototype.setHsv_ = function(opt_hue,
<a name="line245"></a>                                                opt_saturation,
<a name="line246"></a>                                                opt_value) {
<a name="line247"></a>  this.hsv_[0] = (opt_hue != null) ? opt_hue : this.hsv_[0];
<a name="line248"></a>  this.hsv_[1] = (opt_saturation != null) ? opt_saturation : this.hsv_[1];
<a name="line249"></a>  this.hsv_[2] = (opt_value != null) ? opt_value : this.hsv_[2];
<a name="line250"></a>  // Hue is multiplied by 360 because the documentation for goog.color is
<a name="line251"></a>  // currently incorrect.
<a name="line252"></a>  // TODO(user): Fix this, see http://1324469 .
<a name="line253"></a>  this.color_ = goog.color.hsvArrayToHex([
<a name="line254"></a>    this.hsv_[0] * 360,
<a name="line255"></a>    this.hsv_[1],
<a name="line256"></a>    this.hsv_[2]
<a name="line257"></a>  ]);
<a name="line258"></a>};
<a name="line259"></a>
<a name="line260"></a>
<a name="line261"></a>/**
<a name="line262"></a> * HsvPalettes cannot be used to decorate pre-existing html, since the
<a name="line263"></a> * structure they build is fairly complicated.
<a name="line264"></a> * @param {Element} element Element to decorate.
<a name="line265"></a> * @return {boolean} Returns always false.
<a name="line266"></a> * @override
<a name="line267"></a> */
<a name="line268"></a>goog.ui.HsvPalette.prototype.canDecorate = function(element) {
<a name="line269"></a>  return false;
<a name="line270"></a>};
<a name="line271"></a>
<a name="line272"></a>
<a name="line273"></a>/** @override */
<a name="line274"></a>goog.ui.HsvPalette.prototype.createDom = function() {
<a name="line275"></a>  var dom = this.getDomHelper();
<a name="line276"></a>  var noalpha = (goog.userAgent.IE &amp;&amp; !goog.userAgent.isVersion(&#39;7&#39;)) ?
<a name="line277"></a>      &#39; &#39; + goog.getCssName(this.className, &#39;noalpha&#39;) : &#39;&#39;;
<a name="line278"></a>
<a name="line279"></a>  var backdrop = dom.createDom(goog.dom.TagName.DIV,
<a name="line280"></a>      goog.getCssName(this.className, &#39;hs-backdrop&#39;));
<a name="line281"></a>
<a name="line282"></a>  this.hsHandleEl_ = dom.createDom(goog.dom.TagName.DIV,
<a name="line283"></a>      goog.getCssName(this.className, &#39;hs-handle&#39;));
<a name="line284"></a>
<a name="line285"></a>  this.hsImageEl_ = dom.createDom(goog.dom.TagName.DIV,
<a name="line286"></a>      goog.getCssName(this.className, &#39;hs-image&#39;),
<a name="line287"></a>      this.hsHandleEl_);
<a name="line288"></a>
<a name="line289"></a>  this.valueBackgroundImageElement = dom.createDom(
<a name="line290"></a>      goog.dom.TagName.DIV,
<a name="line291"></a>      goog.getCssName(this.className, &#39;v-image&#39;));
<a name="line292"></a>
<a name="line293"></a>  this.vHandleEl_ = dom.createDom(
<a name="line294"></a>      goog.dom.TagName.DIV,
<a name="line295"></a>      goog.getCssName(this.className, &#39;v-handle&#39;));
<a name="line296"></a>
<a name="line297"></a>  this.swatchElement = dom.createDom(goog.dom.TagName.DIV,
<a name="line298"></a>      goog.getCssName(this.className, &#39;swatch&#39;));
<a name="line299"></a>
<a name="line300"></a>  this.inputElement = dom.createDom(&#39;input&#39;, {
<a name="line301"></a>    &#39;class&#39;: goog.getCssName(this.className, &#39;input&#39;),
<a name="line302"></a>    &#39;type&#39;: &#39;text&#39;, &#39;dir&#39;: &#39;ltr&#39;
<a name="line303"></a>  });
<a name="line304"></a>
<a name="line305"></a>  var labelElement = dom.createDom(&#39;label&#39;, null, this.inputElement);
<a name="line306"></a>
<a name="line307"></a>  var element = dom.createDom(goog.dom.TagName.DIV,
<a name="line308"></a>      this.className + noalpha,
<a name="line309"></a>      backdrop,
<a name="line310"></a>      this.hsImageEl_,
<a name="line311"></a>      this.valueBackgroundImageElement,
<a name="line312"></a>      this.vHandleEl_,
<a name="line313"></a>      this.swatchElement,
<a name="line314"></a>      labelElement);
<a name="line315"></a>
<a name="line316"></a>  this.setElementInternal(element);
<a name="line317"></a>
<a name="line318"></a>  // TODO(arv): Set tabIndex
<a name="line319"></a>};
<a name="line320"></a>
<a name="line321"></a>
<a name="line322"></a>/**
<a name="line323"></a> * Renders the color picker inside the provided element. This will override the
<a name="line324"></a> * current content of the element.
<a name="line325"></a> * @override
<a name="line326"></a> */
<a name="line327"></a>goog.ui.HsvPalette.prototype.enterDocument = function() {
<a name="line328"></a>  goog.ui.HsvPalette.superClass_.enterDocument.call(this);
<a name="line329"></a>
<a name="line330"></a>  // TODO(user): Accessibility.
<a name="line331"></a>
<a name="line332"></a>  this.updateUi();
<a name="line333"></a>
<a name="line334"></a>  var handler = this.getHandler();
<a name="line335"></a>  handler.listen(this.getElement(), goog.events.EventType.MOUSEDOWN,
<a name="line336"></a>      this.handleMouseDown, false, this);
<a name="line337"></a>
<a name="line338"></a>  // Cannot create InputHandler in createDom because IE throws an exception
<a name="line339"></a>  // on document.activeElement
<a name="line340"></a>  if (!this.inputHandler_) {
<a name="line341"></a>    this.inputHandler_ = new goog.events.InputHandler(this.inputElement);
<a name="line342"></a>  }
<a name="line343"></a>
<a name="line344"></a>  handler.listen(this.inputHandler_,
<a name="line345"></a>      goog.events.InputHandler.EventType.INPUT, this.handleInput, false, this);
<a name="line346"></a>};
<a name="line347"></a>
<a name="line348"></a>
<a name="line349"></a>/** @override */
<a name="line350"></a>goog.ui.HsvPalette.prototype.disposeInternal = function() {
<a name="line351"></a>  goog.ui.HsvPalette.superClass_.disposeInternal.call(this);
<a name="line352"></a>
<a name="line353"></a>  delete this.hsImageEl_;
<a name="line354"></a>  delete this.hsHandleEl_;
<a name="line355"></a>  delete this.valueBackgroundImageElement;
<a name="line356"></a>  delete this.vHandleEl_;
<a name="line357"></a>  delete this.swatchElement;
<a name="line358"></a>  delete this.inputElement;
<a name="line359"></a>  if (this.inputHandler_) {
<a name="line360"></a>    this.inputHandler_.dispose();
<a name="line361"></a>    delete this.inputHandler_;
<a name="line362"></a>  }
<a name="line363"></a>  goog.events.unlistenByKey(this.mouseMoveListener_);
<a name="line364"></a>  goog.events.unlistenByKey(this.mouseUpListener_);
<a name="line365"></a>};
<a name="line366"></a>
<a name="line367"></a>
<a name="line368"></a>/**
<a name="line369"></a> * Updates the position, opacity, and styles for the UI representation of the
<a name="line370"></a> * palette.
<a name="line371"></a> * @protected
<a name="line372"></a> */
<a name="line373"></a>goog.ui.HsvPalette.prototype.updateUi = function() {
<a name="line374"></a>  if (this.isInDocument()) {
<a name="line375"></a>    var h = this.hsv_[0];
<a name="line376"></a>    var s = this.hsv_[1];
<a name="line377"></a>    var v = this.hsv_[2];
<a name="line378"></a>
<a name="line379"></a>    var left = this.hsImageEl_.offsetWidth * h;
<a name="line380"></a>
<a name="line381"></a>    // We don&#39;t use a flipped gradient image in RTL, so we need to flip the
<a name="line382"></a>    // offset in RTL so that it still hovers over the correct color on the
<a name="line383"></a>    // gradiant.
<a name="line384"></a>    if (this.isRightToLeft()) {
<a name="line385"></a>      left = this.hsImageEl_.offsetWidth - left;
<a name="line386"></a>    }
<a name="line387"></a>
<a name="line388"></a>    // We also need to account for the handle size.
<a name="line389"></a>    var handleOffset = Math.ceil(this.hsHandleEl_.offsetWidth / 2);
<a name="line390"></a>    left -= handleOffset;
<a name="line391"></a>
<a name="line392"></a>    var top = this.hsImageEl_.offsetHeight * (1 - s);
<a name="line393"></a>    // Account for the handle size.
<a name="line394"></a>    top -= Math.ceil(this.hsHandleEl_.offsetHeight / 2);
<a name="line395"></a>
<a name="line396"></a>    goog.style.bidi.setPosition(this.hsHandleEl_, left, top,
<a name="line397"></a>        this.isRightToLeft());
<a name="line398"></a>
<a name="line399"></a>    top = this.valueBackgroundImageElement.offsetTop -
<a name="line400"></a>        Math.floor(this.vHandleEl_.offsetHeight / 2) +
<a name="line401"></a>        this.valueBackgroundImageElement.offsetHeight * ((255 - v) / 255);
<a name="line402"></a>
<a name="line403"></a>    this.vHandleEl_.style.top = top + &#39;px&#39;;
<a name="line404"></a>    goog.style.setOpacity(this.hsImageEl_, (v / 255));
<a name="line405"></a>
<a name="line406"></a>    goog.style.setStyle(this.valueBackgroundImageElement, &#39;background-color&#39;,
<a name="line407"></a>        goog.color.hsvToHex(this.hsv_[0] * 360, this.hsv_[1], 255));
<a name="line408"></a>
<a name="line409"></a>    goog.style.setStyle(this.swatchElement, &#39;background-color&#39;, this.color_);
<a name="line410"></a>    goog.style.setStyle(this.swatchElement, &#39;color&#39;,
<a name="line411"></a>                        (this.hsv_[2] &gt; 255 / 2) ? &#39;#000&#39; : &#39;#fff&#39;);
<a name="line412"></a>    this.updateInput();
<a name="line413"></a>  }
<a name="line414"></a>};
<a name="line415"></a>
<a name="line416"></a>
<a name="line417"></a>/**
<a name="line418"></a> * Handles mousedown events on palette UI elements.
<a name="line419"></a> * @param {goog.events.BrowserEvent} e Event object.
<a name="line420"></a> * @protected
<a name="line421"></a> */
<a name="line422"></a>goog.ui.HsvPalette.prototype.handleMouseDown = function(e) {
<a name="line423"></a>  if (e.target == this.valueBackgroundImageElement ||
<a name="line424"></a>      e.target == this.vHandleEl_) {
<a name="line425"></a>    // Setup value change listeners
<a name="line426"></a>    var b = goog.style.getBounds(this.valueBackgroundImageElement);
<a name="line427"></a>    this.handleMouseMoveV_(b, e);
<a name="line428"></a>    this.mouseMoveListener_ = goog.events.listen(this.document_,
<a name="line429"></a>        goog.events.EventType.MOUSEMOVE,
<a name="line430"></a>        goog.bind(this.handleMouseMoveV_, this, b));
<a name="line431"></a>    this.mouseUpListener_ = goog.events.listen(this.document_,
<a name="line432"></a>        goog.events.EventType.MOUSEUP, this.handleMouseUp, false, this);
<a name="line433"></a>  } else if (e.target == this.hsImageEl_ || e.target == this.hsHandleEl_) {
<a name="line434"></a>    // Setup hue/saturation change listeners
<a name="line435"></a>    var b = goog.style.getBounds(this.hsImageEl_);
<a name="line436"></a>    this.handleMouseMoveHs_(b, e);
<a name="line437"></a>    this.mouseMoveListener_ = goog.events.listen(this.document_,
<a name="line438"></a>        goog.events.EventType.MOUSEMOVE,
<a name="line439"></a>        goog.bind(this.handleMouseMoveHs_, this, b));
<a name="line440"></a>    this.mouseUpListener_ = goog.events.listen(this.document_,
<a name="line441"></a>        goog.events.EventType.MOUSEUP, this.handleMouseUp, false, this);
<a name="line442"></a>  }
<a name="line443"></a>};
<a name="line444"></a>
<a name="line445"></a>
<a name="line446"></a>/**
<a name="line447"></a> * Handles mousemove events on the document once a drag operation on the value
<a name="line448"></a> * slider has started.
<a name="line449"></a> * @param {goog.math.Rect} b Boundaries of the value slider object at the start
<a name="line450"></a> *     of the drag operation.
<a name="line451"></a> * @param {goog.events.BrowserEvent} e Event object.
<a name="line452"></a> * @private
<a name="line453"></a> */
<a name="line454"></a>goog.ui.HsvPalette.prototype.handleMouseMoveV_ = function(b, e) {
<a name="line455"></a>  e.preventDefault();
<a name="line456"></a>  var vportPos = this.getDomHelper().getDocumentScroll();
<a name="line457"></a>
<a name="line458"></a>  var height = Math.min(
<a name="line459"></a>      Math.max(vportPos.y + e.clientY, b.top),
<a name="line460"></a>      b.top + b.height);
<a name="line461"></a>
<a name="line462"></a>  var newV = Math.round(
<a name="line463"></a>      255 * (b.top + b.height - height) / b.height);
<a name="line464"></a>
<a name="line465"></a>  this.setHsv(null, null, newV);
<a name="line466"></a>};
<a name="line467"></a>
<a name="line468"></a>
<a name="line469"></a>/**
<a name="line470"></a> * Handles mousemove events on the document once a drag operation on the
<a name="line471"></a> * hue/saturation slider has started.
<a name="line472"></a> * @param {goog.math.Rect} b Boundaries of the value slider object at the start
<a name="line473"></a> *     of the drag operation.
<a name="line474"></a> * @param {goog.events.BrowserEvent} e Event object.
<a name="line475"></a> * @private
<a name="line476"></a> */
<a name="line477"></a>goog.ui.HsvPalette.prototype.handleMouseMoveHs_ = function(b, e) {
<a name="line478"></a>  e.preventDefault();
<a name="line479"></a>  var vportPos = this.getDomHelper().getDocumentScroll();
<a name="line480"></a>  var newH = (Math.min(Math.max(vportPos.x + e.clientX, b.left),
<a name="line481"></a>      b.left + b.width) - b.left) / b.width;
<a name="line482"></a>  var newS = (-Math.min(Math.max(vportPos.y + e.clientY, b.top),
<a name="line483"></a>      b.top + b.height) + b.top + b.height) / b.height;
<a name="line484"></a>  this.setHsv(newH, newS, null);
<a name="line485"></a>};
<a name="line486"></a>
<a name="line487"></a>
<a name="line488"></a>/**
<a name="line489"></a> * Handles mouseup events on the document, which ends a drag operation.
<a name="line490"></a> * @param {goog.events.Event} e Event object.
<a name="line491"></a> * @protected
<a name="line492"></a> */
<a name="line493"></a>goog.ui.HsvPalette.prototype.handleMouseUp = function(e) {
<a name="line494"></a>  goog.events.unlistenByKey(this.mouseMoveListener_);
<a name="line495"></a>  goog.events.unlistenByKey(this.mouseUpListener_);
<a name="line496"></a>};
<a name="line497"></a>
<a name="line498"></a>
<a name="line499"></a>/**
<a name="line500"></a> * Handles input events on the hex value input field.
<a name="line501"></a> * @param {goog.events.Event} e Event object.
<a name="line502"></a> * @protected
<a name="line503"></a> */
<a name="line504"></a>goog.ui.HsvPalette.prototype.handleInput = function(e) {
<a name="line505"></a>  if (/^#[0-9a-f]{6}$/i.test(this.inputElement.value)) {
<a name="line506"></a>    this.setColor(this.inputElement.value);
<a name="line507"></a>  }
<a name="line508"></a>};
</pre>


</body>
</html>
